package com.itnoob.factory;

import com.itnoob.strategy.PayStrategy;
import com.itnoob.type.PayTypeEnum;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhoujun
 * @date 2025/3/19 23:29
 */
@Service
public class PayStrategyFactory {

    private Map<String, PayStrategy> strategyMap = new HashMap<>();

    public PayStrategyFactory(@Qualifier("weChatPayStrategyImpl") PayStrategy weChatPayStrategy,
                              @Qualifier("aliPayStrategyImpl") PayStrategy aliPayStrategy){
        strategyMap.put(PayTypeEnum.WECHAT_PAY.getValue(),weChatPayStrategy);
        strategyMap.put(PayTypeEnum.ALI_PAY.getValue(),aliPayStrategy);
    }

    /**
     * 根据支付类型来获取对应的策略对象
     * @param payTypeEnum
     * @return
     */
    public PayStrategy  getPayStrategy(PayTypeEnum payTypeEnum){
        return strategyMap.get(payTypeEnum.getValue());
    }
}
